package com.vieewer.btdemo.utils

import android.animation.ObjectAnimator
import android.content.Context
import android.util.Log
import android.util.TypedValue
import android.widget.ImageView


class UIUtils {

    companion object {

        // 动画实际执行
        fun startPropertyAnim(view : ImageView, radio : Float) {
            // 第二个参数"rotation"表明要执行旋转
            // 0f -> 360f，从旋转360度，也可以是负值，负值即为逆时针旋转，正值是顺时针旋转。
            var anim = ObjectAnimator.ofFloat(view, "rotation", radio)
            // 动画的持续时间，执行多久
            anim.duration = 500
            anim.addUpdateListener { animation ->
                var value = animation!!.animatedValue
                Log.d("yjj", value.toString() + "")
            }
            anim.start()
        }




        fun getAngle(orientation: String?): Int {
            var angle = -1
            when (orientation) {
                //1左，2左前，3前，4右前，5右
                "1" -> {
                    angle = 0
                }
                "2" -> {
                    angle = 45
                }
                "3" -> {
                    angle = 90
                }
                "4" -> {
                    angle = 135
                }
                "5" -> {
                    angle = 180
                }
            }
            return angle
        }


        fun convertDipToPixels(context: Context, dip: Int): Int {
            val resources = context.resources
            val px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip.toFloat(), resources.displayMetrics)
            return px.toInt()
        }


    }







}